﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using WeShare.WeiXin.Applet.Qr.Entity;
using WeShare.WeiXin.Common;
using WeShare.WeiXin.Common.EnumKey;

namespace WeShare.WeiXin.Applet.Qr
{
    public class QrApi
    {
        public static BaseRes GetA(CodeAReq req, FileStreamInfo stream, string tokenOrAppId = "")
        {
            var url = $"https://api.weixin.qq.com/wxa/getwxacode?access_token={OpenApi.GetToken(tokenOrAppId,PlatformType.Mini)}";
            var res = Utils.DownLoadByPostResult(url, req, stream);
            if (string.IsNullOrEmpty(res))
            {
                return new BaseRes { errcode = 0 };
            }
            else
            {
                return JsonConvert.DeserializeObject<BaseRes>(res);
            }
        }
        public static BaseRes GetB(CodeBReq req, FileStreamInfo stream, string tokenOrAppId = "")
        {
            var url = $"https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={OpenApi.GetToken(tokenOrAppId, PlatformType.Mini)}";
            var res = Utils.DownLoadByPostResult(url, req, stream);
            if (string.IsNullOrEmpty(res))
            {
                return new BaseRes { errcode = 0 };
            }
            else
            {
                return JsonConvert.DeserializeObject<BaseRes>(res);
            }
        }
        public static BaseRes GetC(CodeCReq req, FileStreamInfo stream, string tokenOrAppId = "")
        {
            var url = $"https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token={OpenApi.GetToken(tokenOrAppId, PlatformType.Mini)}";
            var res = Utils.DownLoadByPostResult(url, req, stream);
            if (string.IsNullOrEmpty(res))
            {
                return new BaseRes { errcode = 0 };
            }
            else
            {
                return JsonConvert.DeserializeObject<BaseRes>(res);
            }
        }
    }
}
